/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.courses.pb138.j2014.projects.soxc.GUI;

import cz.muni.fi.courses.pb138.j2014.projects.soxc.difftree.DocumentDiffTree;
import cz.muni.fi.courses.pb138.j2014.projects.soxc.difftree.NodeDiffTree;
import cz.muni.fi.courses.pb138.j2014.projects.soxc.difftree.consumers.JustDocumentDiffTreeConsumer;
import java.util.List;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author Jakub Kremláček
 */
public final class GUIDisplay extends javax.swing.JFrame {
    
    JustDocumentDiffTreeConsumer consumer;
    DefaultMutableTreeNode topLeft = new DefaultMutableTreeNode("File #1");
    DefaultMutableTreeNode topRight = new DefaultMutableTreeNode("File #2");
    DefaultTreeModel treeModelLeft = new DefaultTreeModel(topLeft);
    DefaultTreeModel treeModelRight = new DefaultTreeModel(topRight);    
    DocumentDiffTree tree;
    
    public GUIDisplay(DocumentDiffTree tree) {
        this.tree = tree;
        
        List<NodeDiffTree> children = tree.getChildren();
        this.getTreeStructure(children, topLeft, topRight);
        initComponents();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        scrollPaneLeft = new javax.swing.JScrollPane();
        jTreeLeft = new javax.swing.JTree();
        scrollPaneRight = new javax.swing.JScrollPane();
        jTreeRight = new javax.swing.JTree();
        closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SOXC GUI");

        jSplitPane1.setDividerLocation(390);

        jTreeLeft.setModel(treeModelLeft);
        scrollPaneLeft.setViewportView(jTreeLeft);

        jSplitPane1.setLeftComponent(scrollPaneLeft);

        jTreeRight.setModel(treeModelRight);
        scrollPaneRight.setViewportView(jTreeRight);

        jSplitPane1.setRightComponent(scrollPaneRight);

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(closeButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closeButton))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_closeButtonActionPerformed

    public void getTreeStructure(List<NodeDiffTree> parents, DefaultMutableTreeNode rootLeft, DefaultMutableTreeNode rootRight) {
        GUITreeFactory factory = new GUITreeFactory(parents, rootLeft, rootRight); 
        factory.processParents();
        factory.addNewNodes();
    }
    
    public void display() { 
        try {
            UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName()); 
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIDisplay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIDisplay(tree).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTreeLeft;
    private javax.swing.JTree jTreeRight;
    private javax.swing.JScrollPane scrollPaneLeft;
    private javax.swing.JScrollPane scrollPaneRight;
    // End of variables declaration//GEN-END:variables
}
